<script setup lang="ts">
import PaneAccount from './pane-account.vue'
import PanePhone from './pane-phone.vue'
import { ref,watch } from 'vue'
import { localCache } from '@/util/cache.ts'
const activeName = ref("account")
const isRemPwd = ref<boolean>(localCache.getCache("isRemPwd"))
const accountRef = ref<instanceType<typeof PaneAccount>>()

watch(isRemPwd, (newValue) => {
  localCache.setCache("isRemPwd",newValue)
})

function handleLoginBtnClick() {
	if ( activeName.value === "account") {
		// 获取子组件的实列
		accountRef.value?.loginAction(isRemPwd.value)

		// 调用方法
	}else {
		console.log(activeName.value)
	}
}

</script>

<template>
	<div class="login-panel">
		<!-- 顶部的标题 -->
		<h1 class="title">智测试平台</h1>

		<!-- 中间tabs的切换 -->
		<div class="tabs">
  			<el-tabs type="border-card" stretch v-model="activeName">

  				<!-- 账号登录的pane -->
    			<el-tab-pane label="帐号登录" name="account">
    				<template #label>
    					<div class="label">
    						<el-icon><UserFilled /></el-icon>
    						<span class="text">帐号登录</span>
    					</div>
    				</template>
    				<PaneAccount ref="accountRef" />
    			</el-tab-pane>

    			<!-- 手机登录的pane -->
    			<el-tab-pane label="手机登录" name="phone">
    				<template #label>
    					<div class="label">
    						<el-icon><Cellphone /></el-icon>
    						<span class="text">手机登录</span>
    					</div>
    				</template>
    				<PanePhone/>
    			</el-tab-pane>
  			</el-tabs>
		</div>
		<div class="controls">
			<el-checkbox v-model="isRemPwd" label="记住密码" size="large" />
			<el-link type="primary">忘记密码</el-link>
		</div>
		<el-button type="primary" class="login-btn" size="large" @click="handleLoginBtnClick">登录</el-button>
	</div>
</template>
<style scoped>
.login-panel {
	width: 330px;
	margin-botton: 15px;
}
.title {
	text-align: center;
	margin-botton: 15px;
}
.label {
	display: flex;
	align-items: center;
	justify-content: center;

	.text {
		margin-left: 10px;
	}
}

.controls {
	margin-top: 12px;
	display: flex;
	justify-content: space-between;
}

.login-btn {
	margin-top: 10px;
	width: 100%;
}
</style>
